package com.jp.code.leetCode;

import java.util.Arrays;

public class MoveZeroes {


    public static void main(String[] args) {


        int[] n = {0, 1, 0, 3, 12};

        moveZero1(n);


        System.out.println(Arrays.toString(n));

    }


    public static void moveZero1(int[] nums) {

        int n = nums.length, left = 0, right = 0;


        // 右边开始移动
        while (right < n) {

            if (nums[right] != 0) {
                swap(nums, left, right);
                left++;
            }
            right++;
        }


    }

    public static void swap(int[] nums, int left, int right) {
        int temp = nums[left];
        nums[left] = nums[right];
        nums[right] = temp;
    }


}
